package com.bawei.module_mine.audit.fragment

import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.viewModels
import com.bawei.lib_common.base.state.Empty
import com.bawei.lib_common.base.state.Failed
import com.bawei.lib_common.base.state.Loading
import com.bawei.lib_common.base.state.Success
import com.bawei.lib_common.base.utils.LoggerUtils
import com.bawei.lib_common.observeWithLifecycle
import com.bawei.module_mine.R
import com.bawei.module_mine.adapter.AuditAllAdapter
import com.bawei.module_mine.adapter.AuditCarAdapter
import com.bawei.module_mine.audit.AuditViewModel
import com.bawei.module_mine.databinding.FragmentCarAuditBinding
import com.bawei.myclub.base.mvvm.view.BaseFragment
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class CarAuditFragment : BaseFragment<AuditViewModel,  FragmentCarAuditBinding>() {
    override val mLayoutResId: Int
        get() = R.layout.fragment_car_audit
    override val mViewModel: AuditViewModel by viewModels()
    private val mAuditCarAdapter: AuditCarAdapter by lazy {
        AuditCarAdapter()
    }
    override fun initView() {
        initAdapter()
    }
    override fun initData() {
        mViewModel.getsParkingList()
    }

    override fun initListener() {
        mViewModel.parkingEvent.observeWithLifecycle(this){
            when(it){
                Empty -> {}
                is Failed -> {}
                Loading -> {}
                Success -> {
                    LoggerUtils.d("fragment2","成功"+mViewModel.parkingList)
                    mAuditCarAdapter.setCarData(mViewModel.parkingList)
                }
            }
        }
    }
    private fun initAdapter() {
        mAuditCarAdapter.setupLayoutManager(mBinding.auditRec)
        mBinding.auditRec.adapter = mAuditCarAdapter
    }

    override fun onResume() {
        super.onResume()
        mViewModel.getsParkingList()
    }
}